<?php
/**
 * Created by PhpStorm.
 * User: yangxu
 * Date: 2016/5/4
 * Time: 9:56
 */

namespace Admin\Controller;
use Think\Controller;

class ShareLinkController extends Controller
{
    private $cat;
    public function __construct(){
        parent::__construct();
        if(!logAdmin(session('adminId'))) header('location:'.U('Admin/Index/login'));
        $this->cat=M('sharelink');
    }
    public function index(){
        $result=$this->cat->find();
        if($result){
        $this->assign('share',$result['shareLink']);
        $this->display('AdsManage/ShareLink');
        }
        else $this->error('读取信息出错');
    }
    public function save(){
        if(IS_POST){
               $data=I('post.');
               $data['shareLink']=$data['shareLink'];
               $num=$this->cat->field('id')->find();
               if($num){
               $map['id']=$num['id'];
               $result=$this->cat->where($map)->save($data);
               $result>=0? $this->ajaxReturn('保存成功'):  $this->ajaxReturn('保存失败');
               }
               else{
               $result=$this->cat->add($data);
               $result>0? $this->ajaxReturn('保存成功'):  $this->ajaxReturn('保存失败');
               }
        }
    }
}